//
//  YTabBarController.swift
//  rxCoreLogic
//
//  Created by yq on 2021/1/26.
//

import UIKit

protocol YTabBarItemProtocol {
	var itemTuple:(image: UIImage, selectedImage: UIImage)? { get }
}

enum ItemType: Int, YTabBarItemProtocol {
	case opera
	case apply
	
	var title: String {
		switch self {
			case .opera:
				return "操作符"
			default:
				return "应用"
		}
	}
	var itemTuple: (image: UIImage, selectedImage: UIImage)? {
		let name = "tabbar_0\(rawValue)"
		let sName = name + "s"
		let image = UIImage(named: name)!
		let selectedImage = UIImage(named: sName)!
		return (image, selectedImage)
	}
}

class YTabBarController: UITabBarController {
	
	let itemTypes: [ItemType] = [.opera, .apply]
	let childVcs = [ ViewController(), OperatorApplyController() ]
	
	
	override func viewDidLoad() {
		super.viewDidLoad()
		
		UITabBar.appearance().tintColor = UIColor.green
		addchildVcs(childVcs, itemTypes: itemTypes)
		tabBar.backgroundImage = UIImage.imageFromColor(color: UIColor.white.withAlphaComponent(0.5))
	}
	
	func addchildVcs(_ vcs: [UIViewController], itemTypes: [ItemType]) {
		for i in 0 ..< vcs.count {
			let item = itemTypes[i]
			vcs[i].tabBarItem = UITabBarItem(title: item.title, image: item.itemTuple?.image, selectedImage: item.itemTuple?.selectedImage)
			let nav = YNaviController(rootViewController: vcs[i])
			addChild(nav)
		}
	}
	
}


